<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link REL="SHORTCUT ICON" HREF="<?php echo base_url() . APPPATH ?>themes/user/img/logo.png"/>
    
    <?php $this->load->view('_meta') ?>
    
    <title>Please select your location</title>
    <link href="<?php echo base_url() . APPPATH ?>themes/welcome/css/site.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="<?php echo base_url() . APPPATH ?>themes/admin/js/jquery/jquery.min.js"></script>	
    <script type="text/javascript">
      var base_url='<?php echo site_url(); ?>';
      var country_id = 0, state_id = 0;
      jQuery(document).ready(function(){
        $('#country_id').bind({
          change: function (){detect_country_search($(this).val());},
          blur: function (){detect_country_search($(this).val());}
        });

        $('#state_id').bind({
          change: function (){detect_state_search($(this).val());},
          blur: function (){detect_state_search($(this).val());}
        }); 	
        detect_country_search($('#country_id').val());        
      });
      function detect_country_search(id){
        if(country_id != id){
          country_id = id;
          $('#state_id').html('<option value=""><?php echo $this->lang->line('label.state.select') ?></option>');
          if(id){
            $.post('<?php echo site_url('admin/ajax/list_json_state') ?>', {id : id}, function(data){		  
              if(data && data.length > 0){
                $.each(data, function(key, value){
                  $('#state_id').append('<option '+
                    (value['id'] == '<?php echo isset($state_id) ? $state_id : 0 ?>' ? 'selected="selected"' :'' )
                    +' value="'+value['id']+'">'+ value['name'] +'</option>');
                  if(value['id'] == '<?php echo isset($state_id) ? $state_id : 0 ?>'){
                    detect_state_search(value['id']);
                  }
                })
              }
            }, 'json');
          }
        }
      }
  
      function detect_state_search(id){
        if(state_id != id){
          state_id = id;
          $('#city_id').html('<option value=""><?php echo $this->lang->line('label.city.select') ?></option>');
          if(id){
            $.post('<?php echo site_url('admin/ajax/list_json_city') ?>', {id : id}, function(data){
              if(data && data.length > 0){
                $.each(data, function(key, value){
                  $('#city_id').append('<option '+
                    (value['id'] == '<?php echo isset($city_id) ? $city_id : 0 ?>' ? 'selected="selected"' :'' )
                    +' value="'+value['id']+'">'+ value['name'] +'</option>');
                })
              }
            }, 'json');
          }
        }
      }
    </script>
  </head>
  <body>
    <div class="wrapper_screen">
      <div class="wrapper_main">
        <div class="head">
          <div class="logo cpos_1"></div>
          <div class="slogan cpos_2"></div>
          <div class="clearer"></div>

        </div>
        <div id="hoala2"><img src="<?php echo base_url() . APPPATH ?>themes/welcome/img/hoala2.png"  /></div>
        <div class="box">
          <div id="stt"><img src="<?php echo base_url() . APPPATH ?>themes/welcome/img/stt2.png" width="100" height="73" /></div>
          <div class="top_box"></div>
          <div class="rp_box">
            <div class="font30">Select your location</div><br />
            <div>
              <form action="" method="post" id="form_search">
                <div id="currencies_block_top">
                  <select name="country_id" id="country_id" <?php echo empty($error_country)?'':'style="color:#FFD700"' ?> >
                    <option value="">Select country ...</option>
                    <?php
                    $ref_objs = $this->country_model->get_all();
                    foreach ($ref_objs as $ref) {
                      ?>
                      <option value="<?php echo $ref["id"] ?>"
                              <?php echo empty($country_id) || $country_id != $ref["id"] ? "" : 'selected="selected"' ?>>
                                <?php echo $this->country_model->to_string($ref) ?>
                      </option>
                    <?php } ?>
                  </select>
                  <select name="state_id" id="state_id" <?php echo empty($error_state)?'':'style="color:#FFD700"' ?>>
                    <option value="">Select state ...</option>
                  </select>
                  <select name="city_id" id="city_id" <?php echo empty($error_city)?'':'style="color:#FFD700"' ?>>
                    <option value="">Select city ...</option>
                  </select>
                </div>
              </form>
            </div>
            <div class="mg10 mg_left80">
              <a href="#" onclick="jQuery('#form_search').submit();return false;">
                <img src="<?php echo base_url() . APPPATH ?>themes/welcome/img/next.jpg" width="108" height="51" /></a></div>
          </div>
          <div class="bt_box">
            <div class="font18 center">
              We’ll show you Free stuff in your area</div>
          </div>

        </div>
        <div class="clearer"></div>
      </div>
    </div>
    <div class="clearer"></div>

  </body>
</html>
